V2EX  ›  英汉词典
Enqueued related words: Mutator Method, Access Modifier

Accessor Method

定义 Definition

accessor method(访问器方法)指在面向对象编程中,用来读取(访问)对象内部属性/字段值的方法,常见形式是 getter(如 getName())。在某些语境下也会与 setter(设置值)并列讨论,但严格来说 setter 更常被称为 mutator method(修改器方法)。

例句 Examples

The class provides an accessor method to get the user’s email.
这个类提供了一个访问器方法来获取用户的电子邮件。

To preserve encapsulation, the library exposes only accessor methods instead of allowing direct field access.
为了保持封装性,这个库只暴露访问器方法,而不允许直接访问字段。

发音 Pronunciation

/ˈæksɛsər ˈmɛθəd/

词源 Etymology

accessor 来自 access(访问、进入)加上表示“人/物的执行者”的后缀 -or,意为“用于访问的东西/方法”。method 源自希腊语 methodos,含“途径、方法”之意。合起来即“用于访问(数据/属性)的方式或方法”。

相关词 Related Words

文学与作品 Literary Works

  • Effective Java(Joshua Bloch)——讨论 Java 设计实践时常涉及通过方法而非直接字段访问来维护封装性(常以访问器/修改器方法为例)。
  • Clean Code(Robert C. Martin)——在命名与封装相关的章节中,经常提到 getter/setter 等访问器方法的使用边界。
  • Design Patterns: Elements of Reusable Object-Oriented Software(Gamma 等)——在讲解面向对象设计与接口隔离时,常与“通过方法访问状态”这一思想相关联。
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   1087 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 206ms · UTC 17:04 · PVG 01:04 · LAX 09:04 · JFK 12:04
♥ Do have faith in what you're doing.